package com.xiaochun.jiankangapp.fragment

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.xiaochun.jiankangapp.base.CViewBinding
import com.xiaochun.jiankangapp.databinding.FragmentInputInfoStep4Binding
import com.xiaochun.jiankangapp.extension.onClick
import com.xiaochun.jiankangapp.extension.showToast

class InputInfoStep4Fragment : InputInfoBaseFragment() {
    @CViewBinding
    lateinit var viewBinding: FragmentInputInfoStep4Binding
    override fun initView(root: View, savedInstanceState: Bundle?) {
        super.initView(root, savedInstanceState)
        viewBinding.next.onClick {
            val phone = viewBinding.phone.text.toString()
            val name = viewBinding.account.text.toString()
            if (TextUtils.isEmpty(phone) || TextUtils.isEmpty(name)) {
                showToast("请输入姓名和手机号")
                return@onClick
            }
            inputViewModel.name = name
            inputViewModel.phone = phone
            showLoading()
            inputViewModel.save {
                hideLoading()
                if (it.isSuccessful) {
                    showToast("保存成功")
                    requireActivity().finish()
                } else {
                    showToast("保存失败，" + it.msg)
                }
            }
        }
    }
}